<!DOCTYPE html>
<html>
<head>
          <meta charset="utf-8">
        <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
        <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
        <link rel="stylesheet" type="text/css" href="../../css/aui.css">
        <link rel="stylesheet" type="text/css" href="../../css/aui-slide.css">
        <link rel="stylesheet" type="text/css" href="../../css/api.css">
        <link rel="stylesheet" type="text/css" href="../../css/checkbox.css">

        <script type="text/javascript" src="../../script/api.js"></script>
        <script type="text/javascript" src="../../script/jquery.min1.js"></script>
        <script type="text/javascript" src="../../script/Popt.js"></script>
    <script type="text/javascript" src="../../script/cityjson.js"></script>
    <script type="text/javascript" src="../../script/citySet.js"></script>
    <script type="text/javascript" src="../../script/area.js"></script>
    
    <style>

html {
            font-size: 70%;
            height: 100%;
            width: 100%;
            display: table;
        }

        body {
            display: table-cell;
            width: 100%;
            height: 100%;
        
        }
        :-moz-placeholder{
            color: #999999;
        }
        ::-moz-placeholder
        {
            color: #999999;
        }
        ::-webkit-input-placeholder{
            color: #999999;
        }
        :-ms-input-placeholder{
            color: #999999;
        }
        .all{
            height: 100%;
            width: 100%;
        }
        .top{
            position: relative;
            background-color: #f7911b;
            height:5rem;
            width: 100%;
            text-align: center;
        }
        .back{
            font-size: 3rem;
            color: white;
            left:-2rem;
            line-height: 4rem;
            position: absolute;
        }
        .sub_upd{
            font-size: 1.5rem;
            color: red;
            line-height: 5rem;
            position: absolute;
            float: right;
            right: 0.66rem;
        }
        .title{
            font-size: 2rem;
            color: white;
            line-height: 5rem;
        }
        .main{
            position: absolute;
            height: 92.32%;
            width: 100%;
            background-color: #f6f6f6;
            overflow: auto;
        }
        .info_item{
            width: 100%;
            height: 5rem;
            border-bottom: 0.1rem solid #e4e4e4;
            background-color: white;
        }
        .tel_tips{
            font-size: 1.5rem;
            color: #999999;
            float: right;
            margin-top: -2.6rem;
            margin-right: 1rem;
        }
        .address_tips{
            font-size: 1.5rem;
            color: #999999;
            float: right;
            margin-top: -2.6rem;
            margin-right: 1rem;
        }
        .item_address_info{
            height: 8rem;
        }
        .item_defau{
            margin-top: 0.2rem;
            border-top: 0.1rem solid #e4e4e4;
        }
        .defau_tips{
            line-height: 5rem;
            font-size:1.5rem; 
            margin-left: 1.5rem;
            font-weight: bold;
        }
        .item_del{
            margin-top: 2rem;
            border-top: 0.1rem solid #e4e4e4;
        }
        .del_btn{
            display: block;
            height: 100%;
            width: 100%;
            font-size: 1.6rem;
            color: red;
            letter-spacing:0.1rem;
            text-align: center;
            line-height: 5rem;
        }
          * { -ms-word-wrap: break-word; word-wrap: break-word; }
    html { -webkit-text-size-adjust: none; text-size-adjust: none; }

    .wrap{width:464px;height:34px;margin:2rem auto;border:0;position:relative;}
    .input{position:absolute;top:0;left:0;width:457px;margin:0;padding-left:5px;height:30px;line-height:30px;font-size:12px;border:1px solid #c9cacb;}
    s{position:absolute;top:1px;right:0;width:32px;height:32px;background:url("img/arrow.png") no-repeat;}
    ._citys { width: 450px; display: inline-block; border:0rem solid #eee; padding: 5px; position: relative; right:5rem;top:20rem;}

    ._citys span { color: #05920a; height: 15px; width: 15px; line-height: 15px; text-align: center; border-radius: 3px; position: absolute; right: -4rem; top: 1rem; border: 1px solid #05920a; cursor: pointer; }
    ._citys0 { width:25rem; height: 34px; line-height: 34px; display: inline-block; border-bottom: 2px solid #05920a; padding: 0px 5px; font-size:14px; font-weight:bold; margin-left:21rem; }
    ._citys0 li { display: inline-block; line-height: 34px; font-size: 15px; color: #888; width: 80px; text-align: center; cursor: pointer; }
    ._citys1 { display: inline-block; padding: 10px 0;    width: 24rem;float: right; margin-right:-6rem;}
    ._citys1 a { width: 83px; height: 35px; display: inline-block; background-color: #f5f5f5; color: #666; margin-left: 6px; margin-top: 3px; line-height: 35px; text-align: center; cursor: pointer; font-size: 12px; border-radius: 5px; overflow: hidden; }
    ._citys1 a:hover { color: #fff; background-color: #05920a; }
    .AreaS { background-color: #05920a !important; color: #fff !important; }
    </style>
</head>
<body>
<div class="all">
    <div class="top">
        <span class="aui-iconfont aui-icon-left" style="float:left;font-size: 2.5rem;line-height: 5rem;" tapmode onclick="backadd_lis()"></span>
        <span class="title">收货地址</span>
        <span class="sub_upd"  onclick="baocun()">保存</span>
    </div>
    <div class="main" id="main">
      
        
    </div>
</div>
</body>
<script type="text/javascript">
    $("body").on('click','#city',function(e){SelCity(this,e);})
    
    </script>
<script type="text/javascript">
    apiready = function() {  

       if($api.getStorage('bianji')==0){
 
        $api.byId('main').innerHTML='  <div class="info_item item_name">'+
           ' <input type="text" id="name" style="color:#999999;height: 4rem;width: 80%;left: 1.5rem;top: 0.5rem;position: relative;font-size: 1.5rem;"  placeholder="收货人" />'+
      '  </div>'+
        '<div class="info_item item_tel">'+
            '<input type="text" id="tel" style="color:#999999;height: 4rem;width: 80%;left: 1.5rem;top: 0.5rem;position: relative;font-size: 1.5rem;"  placeholder="联系电话" />'+
          '  <span class="tel_tips">+86 ></span>'+
      '  </div>'+
       ' <div class="info_item item_address">'+
          '  <input id="city"  id="city" name="address" style="color:#999999;height: 4rem;width: 80%;left: 1.5rem;top: 0.5rem;position: relative;font-size: 1.5rem;" placeholder="所在地区" readonly/>'+
           ' <span class="address_tips"></span>'+
      ' </div>'+
       ' <div class="info_item item_address_info">'+
           ' <textarea id="address_info" style="color:#999999;height: 6rem;width: 90%;left: 1.5rem;top: 0.5rem;position: relative;font-size: 1.5rem;" placeholder="详细地址" maxlength="50"></textarea>'+
       ' </div>'+
       ' <div class="info_item item_defau">'+
           ' <span class="defau_tips">设为默认地址</span>'+
            '<label class="el-switch el-switch-green" style="float:right;margin-top:0.8rem;margin-right:1.5rem;">'+
               ' <input type="checkbox" name="switch" checked id="check">'+
                '<span class="el-switch-style"></span>'+
           ' </label>'+
        '</div>'
        window.backadd_lis = function () {
            
            api.sendEvent(
                {
                  name:'address',
                  extra:{
                      key1:'ok',
                      key2:'ss'
                  }
                }
            );
            api.closeWin();
            
  }
  // 
  // $api.byId('tel')
  // $api.byId('city')
  // $api.byId('address_info')
  // $api.byId('check').value

  

  window.baocun =function (){
     if( $api.byId('name').value =="" || $api.byId('city').value=="" || $api.byId('address_info').value=="" || $api.byId('tel').value ==""){
    
      // api.addEventListener({
      //     name:'aadress'
      // },function(ret,err){
      //    alert('aaa');
      // });
      alert('信息未完善');
// $api.getStorage('id')

     }else{
      if($("input[type='checkbox']").is(':checked')){
     var defaultt=1;
      }else{
          var defaultt=0;
      }
      var token = $api.getStorage('token');
      var name=$api.byId('name').value;
      var tel=$api.byId('tel').value;
      var address=$api.byId('city').value;
      var name=$api.byId('name').value;
      var address_main=$api.byId('address_info').value;

      var token = {
          token: token,
          name:name,
          tel:tel,
          address:address,
          address_main:address_main,
          default : defaultt,
          do:'add'
      };
  api.ajax({
      url: 'http://www.mk517.com/webApi/address_list.php',
      method: 'post',
      "headers": {
          "Content-Type": "application/json"
      },
      dataType: "json",
      data: {
          body: token
         
      }
  }, function(ret, err) {
      // alert(JSON.stringify(ret));
      if (ret) {
        if(ret.sta==1){
           
          alert("添加成功");
        }else{
          alert("添加失败");
        }
          
       }else {
          alert(JSON.stringify(err));
      }
  });
     }


}






       }else{
        var id=$api.getStorage('id');
        
        var token = $api.getStorage('token');
       
 	var token = {
                token: token,
                id:id,
                do:'upd_from'
            };
        api.ajax({
            url: 'http://www.mk517.com/webApi/address_list.php',
            method: 'post',
            "headers": {
                "Content-Type": "application/json"
            },
            dataType: "json",
            data: {
                body: token
            }
        }, function(ret, err) {
            // alert(JSON.stringify(ret));
            if (ret) {
              if(ret.default==1){
                $api.byId('main').innerHTML='  <div class="info_item item_name">'+
           ' <input type="text" id="name" style="color:#999999;height: 4rem;width: 80%;left: 1.5rem;top: 0.5rem;position: relative;font-size: 1.5rem;" value="'+ ret.name+'" />'+
      '  </div>'+
        '<div class="info_item item_tel">'+
            '<input type="text" id="tel" style="color:#999999;height: 4rem;width: 80%;left: 1.5rem;top: 0.5rem;position: relative;font-size: 1.5rem;"  value="'+ ret.tel+'"  />'+
          '  <span class="tel_tips">+86 ></span>'+
      '  </div>'+
       ' <div class="info_item item_address">'+
          '  <input id="city"  id="city" name="address" style="color:#999999;height: 4rem;width: 80%;left: 1.5rem;top: 0.5rem;position: relative;font-size: 1.5rem;" value="'+ ret.address+'"  readonly/>'+
           ' <span class="address_tips"></span>'+
      ' </div>'+
       ' <div class="info_item item_address_info">'+
           ' <textarea id="address_info" style="color:#999999;height: 6rem;width: 90%;left: 1.5rem;top: 0.5rem;position: relative;font-size: 1.5rem;" value="'+ ret.address_main+'"  maxlength="50"></textarea>'+
       ' </div>'+
       ' <div class="info_item item_defau">'+
           ' <span class="defau_tips">设为默认地址</span>'+
            '<label class="el-switch el-switch-green" style="float:right;margin-top:0.8rem;margin-right:1.5rem;">'+
               ' <input type="checkbox" name="switch" checked  id="check">'+
                '<span class="el-switch-style"></span>'+
           ' </label>'+
        '</div>'+
       ' <div class="info_item item_del">'+
            '<span class="del_btn" onclick="dell()">删除收货地址</span>'+
       '</div>'
              }else{
                  
                $api.byId('main').innerHTML='  <div class="info_item item_name">'+
           ' <input type="text" id="name" style="color:#999999;height: 4rem;width: 80%;left: 1.5rem;top: 0.5rem;position: relative;font-size: 1.5rem;" value="'+ ret.name+'" />'+
      '  </div>'+
        '<div class="info_item item_tel">'+
            '<input type="text" id="tel" style="color:#999999;height: 4rem;width: 80%;left: 1.5rem;top: 0.5rem;position: relative;font-size: 1.5rem;"  value="'+ ret.tel+'"  />'+
          '  <span class="tel_tips">+86 ></span>'+
      '  </div>'+
       ' <div class="info_item item_address">'+
          '  <input id="city"  id="city" name="address" style="color:#999999;height: 4rem;width: 80%;left: 1.5rem;top: 0.5rem;position: relative;font-size: 1.5rem;" value="'+ ret.address+'"  readonly/>'+
           ' <span class="address_tips"></span>'+
      ' </div>'+
       ' <div class="info_item item_address_info">'+
           ' <textarea id="address_info" style="color:#999999;height: 6rem;width: 90%;left: 1.5rem;top: 0.5rem;position: relative;font-size: 1.5rem;"  maxlength="50">'+ ret.address_main+'</textarea>'+
       ' </div>'+
       ' <div class="info_item item_defau">'+
           ' <span class="defau_tips">设为默认地址</span>'+
            '<label class="el-switch el-switch-green" style="float:right;margin-top:0.8rem;margin-right:1.5rem;">'+
               ' <input type="checkbox" name="switch"  id="check">'+
                '<span class="el-switch-style"></span>'+
           ' </label>'+
        '</div>'+
       ' <div class="info_item item_del">'+
            '<span class="del_btn" onclick="dell()">删除收货地址</span>'+
       '</div>'
              }


              window.dell = function () {
                var id=$api.getStorage('id');
        
        var token = $api.getStorage('token');
       
 	var token = {
                token: token,
                id:id,
                do:'del'
            };
        api.ajax({
            url: 'http://www.mk517.com/webApi/address_list.php',
            method: 'post',
            "headers": {
                "Content-Type": "application/json"
            },
            dataType: "json",
            data: {
                body: token
            }
        }, function(ret, err) {
            // alert(JSON.stringify(ret));
            if (ret) {
        alert("删除成功");
            }
        })


              }
              window.backadd_lis = function () {
            
            api.sendEvent(
                {
                  name:'address',
                  extra:{
                      key1:'ok',
                      key2:'ss'
                  }
                }
            );
            api.closeWin();
            
  }

  
  window.baocun =function (){
     if( $api.byId('name').value =="" || $api.byId('city').value=="" || $api.byId('address_info').value=="" || $api.byId('tel').value ==""){
    
      // api.addEventListener({
      //     name:'aadress'
      // },function(ret,err){
      //    alert('aaa');
      // });
      alert('信息未完善');
// $api.getStorage('id')

     }else{
      if($("input[type='checkbox']").is(':checked')){
     var defaultt=1;
      }else{
          var defaultt=0;
      }
      var token = $api.getStorage('token');
      var name=$api.byId('name').value;
      var tel=$api.byId('tel').value;
      var address=$api.byId('city').value;
      var name=$api.byId('name').value;
      var address_main=$api.byId('address_info').value;
      var id=$api.getStorage('id');
      var token = {
          token: token,
          name:name,
          tel:tel,
          address:address,
          address_main:address_main,
          default : defaultt,
          do:'upd',
          id:id
      };
  api.ajax({
      url: 'http://www.mk517.com/webApi/address_list.php',
      method: 'post',
      "headers": {
          "Content-Type": "application/json"
      },
      dataType: "json",
      data: {
          body: token
         
      }
  }, function(ret, err) {
      // alert(JSON.stringify(ret));
      if (ret) {
        if(ret.sta==1){
           
          alert("修改成功");
        }else{
          alert("修改失败");
        }
          
       }else {
          alert(JSON.stringify(err));
      }
  });
     }


}
      
             }else {
                alert(JSON.stringify(err));
            }
        });

       }
       
    }
 </script> 
</html>